package com.singletonapps.evory.entities;


import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;

import com.singletonapps.evory.dto.RoleDto;

@Entity
@Table(name = "ROLE")
public class Role implements Serializable {
	
    private static final long serialVersionUID = 9222237521784764495L;

    @Id
	@SequenceGenerator(name="role_seq", sequenceName="SEQ_ROLE_ID")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "role_seq")
	@Column(name = "ID")
	private Long id;
	
	@Column(name = "ROLE_NAME")
	private String roleName;
	
	@ManyToMany(cascade = CascadeType.ALL, mappedBy = "role")
	private List<User> user;
	
	@Column(name = "DATE_CREATE")
	private Date dateCreate;
	
	@Column(name = "DATE_UPDATE")
	private Date dateUpdate;
	
	@Version
	@Column(name = "VERSION")
	private Long version;
	
	public Role() {}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public Date getDateCreate() {
		return dateCreate;
	}

	public void setDateCreate(Date dateCreate) {
		this.dateCreate = new Date(dateCreate.getTime());
	}

	public Date getDateUpdate() {
		return dateUpdate;
	}

	public void setDateUpdate(Date dateUpdate) {
		this.dateUpdate = new Date(dateUpdate.getTime());
	}

	public Long getVersion() {
		return version;
	}

	public void setVersion(Long version) {
		this.version = version;
	}

	public List<User> getUser() {
		return user;
	}

	public void setUser(List<User> user) {
		this.user = user;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public RoleDto toDto(){
	    RoleDto dto = new RoleDto();
	    dto.setId(this.id);
	    dto.setRoleName(this.roleName);
	    dto.setDateCreate(this.dateCreate);
	    dto.setDateUpdate(this.dateUpdate);
	    dto.setVersion(this.version);
	    return dto;
	}
	
}
